package com.ccit.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ccit.common.result.Result;
import com.ccit.model.Suggestion;
import com.ccit.order.service.SuggestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/suggestion")
public class SuggestionController {
    @Autowired
    private SuggestionService suggestionService;


    @PostMapping("/add")
    public Result<String> add(@RequestBody Suggestion suggestion) {
        suggestionService.addSuggestion(suggestion);
        return Result.ok("保存成功");
    }

    @GetMapping("deleteByUuid")
    public Result<String> deleteByUuid(@RequestParam String uuid) {
        suggestionService.deleteSuggestion(uuid);
        return Result.ok("删除成功");
    }

    @PostMapping("/update")
    public Result<String> update(@RequestBody Suggestion suggestion) {
        suggestionService.updateSuggestion(suggestion);
        return Result.ok("修改成功");
    }

    /*一个查询搞定分页和按手机号筛选*/
    @GetMapping("/getByPhone")
    public Result<IPage<Suggestion>> getByPhone(@RequestParam(required = false) String phone,
                                                @RequestParam(required = false) Integer pageNum,
                                                @RequestParam(required = false) Integer pageSize,
                                                @RequestParam String status) {
        return Result.ok(suggestionService.getByPhone(phone, pageNum, pageSize,status));
    }


}
